package com.tengfei.main.user.service.select;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tengfei.common.utils.poi.select.ExcelDynamicSelect;
import com.tengfei.common.utils.spring.SpringUtils;
import com.tengfei.main.system.domain.SysDept;
import com.tengfei.main.system.mapper.SysDeptMapper;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author feige
 * @version v1.0
 * @date 2022-10-18-21:21
 * @description excel生成下拉框
 */
public class DeptSelectList implements ExcelDynamicSelect {
    @Override
    public String[] getSource(Map<String, String> map) {
        SysDeptMapper mapper = SpringUtils.getBean(SysDeptMapper.class);
        List<SysDept> sysDepts = mapper.selectList(new LambdaQueryWrapper<SysDept>()
                .ne(SysDept::getParentId, 0)
                .eq(SysDept::getShowStatus, 1)
                .eq(SysDept::getStatus, 1)
                .orderByAsc(SysDept::getOrderNum));
        List<String> collect = sysDepts.stream().map(item -> item.getDeptName()).collect(Collectors.toList());
        return collect.toArray(new String[collect.size()]);
    }
}
